package com.yihuan.controller;

import com.yihuan.entity.MoneyEntity;
import com.yihuan.global.MessageConstant;
import com.yihuan.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author:梦醒
 * Date: 2022/5/6 9:25
 * Dream:
 * 信言不美，美言不信。
 * 善者不辩，辩者不善。
 * 知者不博，博者不知。
 * Function:
 */
@RestController
public class MoneyController {
    int pageNumber = 0;
    int count = 0;
    //使用map存储数据
    private Map<String, Object> map = new HashMap<>();
    //数据页数和起始值
    private int num;
    @Autowired
    MoneyService moneyService;
    
    /**
     * 计算每月份额
     *
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("/findMoneyBySumUserMoneyPrice")
    public Map<String, Object> findMoneyBySumUserMoneyPrice(@RequestBody MoneyEntity model, HttpSession session) {
        model.setUsersID((Integer) session.getAttribute("UserID_3"));
        List<MoneyEntity> findMoneyBySumUserMoneyPrice = moneyService.findMoneyBySumUserMoneyPrice(model);
        if (findMoneyBySumUserMoneyPrice.size() == 0) {
            map.put("code", MessageConstant.FALL_CODE);
            map.put("explain ", MessageConstant.MONEY_SELECT_FALL);
            return map;
        }
        map.put("code", MessageConstant.SUCCESS_CODE);
        map.put("money_list", findMoneyBySumUserMoneyPrice);
        map.put("explain ", MessageConstant.MONEY_SELECT_SUCCESS);
        return map;
    }
}
